define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'apply/index' + location.search,
                    // edit_url: 'apply/edit',
                    del_url: 'apply/del',
                    multi_url: 'apply/multi',
                    import_url: 'apply/import',
                    table: 'apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('已申请'),"1":__('已通过'),"2":__('已拒绝')}, formatter: Table.api.formatter.status},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                        buttons: [
                                {
                                    name: 'pass',
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    text: '通过',
                                    refresh:true,
                                    // visible:function(row, value){
                                    //     console.log(row)
                                    //     if(row.status==0){
                                    //         return true
                                    //     }else{
                                    //         return false
                                    //     }
                                    // },
                                    // confirm: '确认点击同意，释放任务',
                                    url: 'membertype/pass?id={user_id}',
                                },

                                {
                                name: 'refuse',
                                title: __('拒绝'),
                                classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
                                refresh:true,
                                text: '拒绝',
                                // visible:function(row, value){
                                //         if(row.status==0){
                                //             return true
                                //         }else{
                                //             return false
                                //         }
                                //     },
                                url: 'membertype/refuse?id={user_id}',
                            },
                                ],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
